﻿using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using SER = CPPEI.ETL.Domain.Services;
using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using VIW = CPPEI.ETL.Domain.Views;

namespace CPPEI.ETL.WebApi.DVPlugIn
{
    /// <summary>
    /// 获取数据审核插件列表
    /// </summary>
    [CPPEI.WebApi.AuthGetAction("DVPLUGIN", "GetPlugIn", "1.0")]
    public class GetPlugInAction : BaseAction<GetPlugInParams, GetPlugInResult>
    {
        protected override ActionResult<GetPlugInResult> OnExecute(ActionContext context,
            SysParameters sysParameters,
            GetPlugInParams opParams)
        {
            SER.DVPlugInService service = new SER.DVPlugInService();

            ServiceResult<VIW.VDVPlugIn> serResult = service.GetPlugIn(opParams.Id);

            if(serResult.IsSuccess)
            {
                GetPlugInResult result = new GetPlugInResult();

                result.Id = serResult.Data.Id;
                result.AssemblyId = serResult.Data.AssemblyId;
                result.Assembly = DefaultValue.GetValue(serResult.Data.Assembly, string.Empty);
                result.Version = DefaultValue.GetValue(serResult.Data.Version, string.Empty);
                result.Name = DefaultValue.GetValue(serResult.Data.Name, string.Empty);
                result.Description = DefaultValue.GetValue(serResult.Data.Description, string.Empty);

                return new ActionResult<GetPlugInResult>(result);
            }
            else
            {
                return new ActionResult<GetPlugInResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class GetPlugInParams
    {
        /// <summary>
        /// 插件的id（PlugInId）
        /// </summary>
        public Guid Id { get; set; }
    }

    public class GetPlugInResult
    {
        public Guid Id { get; set; }

        public Guid AssemblyId { get; set; }

        public string Assembly { get; set; }

        public string Version { get; set; }

        public string Name { get; set; }

        public string Description { get; set; }
    }
}
